import { createStore } from './woniu-redux'

function counter(state=0, action) {
    console.log(state, action)
    switch (action.type) {
        case 'increase gun':
            return state + 1
        case 'decrease gun':
            return state - 1
        default:
            return 10
    }
}

const store = createStore(counter)
const init = store.getState()
console.log(`init gun num: ${init}`)

function listener() {
    const current = store.getState()
    console.log(`current gun num: ${current}`)
}

store.subscribe(listener)

store.dispatch({type: 'increase gun'})
store.dispatch({type: 'increase gun'})
store.dispatch({type: 'increase gun'})
store.dispatch({type: 'decrease gun'})
store.dispatch({type: 'decrease gun'})